package com.wanmait.employment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.employment.entity.EducationalExperience;
import com.wanmait.employment.entity.Userinfo;
import com.wanmait.employment.mapper.EducationalExperienceMapper;
import com.wanmait.employment.mapper.UserinfoMapper;
import com.wanmait.employment.service.EducationalExperienceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service
public class EducationalExperienceServiceImpl implements EducationalExperienceService {
    @Resource
    private EducationalExperienceMapper educationalExperienceMapper;
    @Resource
    private UserinfoMapper userinfoMapper;
    @Override
    public PageInfo<EducationalExperience> selectList(String title, int pageNum, int pagesSize) {
        PageHelper.startPage(pageNum,pagesSize);
        QueryWrapper<EducationalExperience> queryWrapper= new QueryWrapper<>();
        queryWrapper.like("college_name",title).or().like("education",title).or().like("major",title).
        or().inSql("userinfo_id", "SELECT id FROM userinfo WHERE name like '%"+title+"%'");
        List<EducationalExperience> educationalExperiences = educationalExperienceMapper.selectList(queryWrapper);
        PageInfo<EducationalExperience> educationalExperiencePageInfo=new PageInfo<>(educationalExperiences);
        educationalExperiencePageInfo.getList().forEach((educationalExperience) -> {
            QueryWrapper<Userinfo> userinfoQueryWrapper=new QueryWrapper<>();
            userinfoQueryWrapper.eq("id",educationalExperience.getUserinfoId());
            Userinfo userinfo=userinfoMapper.selectOne(userinfoQueryWrapper);
            educationalExperience.setUserinfo(userinfo);
        });
        return educationalExperiencePageInfo;
    }

    @Override
    public Integer update(EducationalExperience educationalExperience) {
        return null;
    }

    @Override
    public Integer insert(EducationalExperience educationalExperience) {
        return null;
    }

    @Override
    public void delete(Integer id) {
         educationalExperienceMapper.deleteById(id);
    }

    @Override
    public List<EducationalExperience> selectId(Integer userinfoId) {
        QueryWrapper<EducationalExperience> educationalExperienceQueryWrapper=new QueryWrapper<>();
        educationalExperienceQueryWrapper.eq("userinfo_id",userinfoId);
        List<EducationalExperience> educationalExperiences=educationalExperienceMapper.selectList(educationalExperienceQueryWrapper);
        return educationalExperiences;
    }
}
